package com.run2code.design.structural.proxy;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
 * 代理模式 - 代理工厂
 * 关注公众号【奔跑的码畜】，一起进步不迷路
 *
 * @author 第七人格
 * @date 2023/12/21
 */
public class GenericProxyFactory {

    GenericService genericService;

    public GenericProxyFactory(String methodName) {
        this.genericService = new DubboServiceImpl();
    }

    private final Map<String, GenericService> genericReferenceCache = new ConcurrentHashMap<>();

    public GenericService newInstance(String methodName) {
        System.out.println("[" + methodName + "]通过代理工厂创建代理");
        return genericReferenceCache.computeIfAbsent(methodName, k -> new GenericProxy(genericService));
    }

}